package com.haidong.arraylist;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * 存储学生信息并查询
 * 测试数据:学号,姓名,年龄,专业
 * ""
 */
public class ArrayListTest2 {
    public static void main(String[] args) {
        //创建集合并存放数据
        ArrayList<Student> ss = new ArrayList<>();
        ss.add(new Student("20191212","小李",24,"工商"));
        ss.add(new Student("20191618","小刘",24,"土木"));
        ss.add(new Student("20195410","小吴",24,"财管"));
        ss.add(new Student("20193320","小张",24,"电信"));


        for (int i = 0;i <3;i++) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入要查找的内容:");
            Student ans = refer(ss,sc.next());
            if(ans!=null){
                System.out.println(ans.getName() + '\t' + ans.getNumber() + '\t' + ans.getAge() + '\t' + ans.getProfess());
            }
        }

    }
    public static Student refer(ArrayList<Student> ss,String input){
        if(input.length()==8){
            for (int i = 0; i < ss.size(); i++) {
                if(ss.get(i).getNumber().equals(input)){
                    return ss.get(i);
                }
            }
        }
        else if(input.length()==2){
            //这里还没写好,先不测试
        }
        return null;
    }
}
